'use strict';
// const { service } = require('../utils/request');
module.exports = {
  async handleWebsocketClient(message, connect) {
    console.log(message);
    const { ctx } = this;
    if (message.type == 700) {
      switch (message.sub_type) {
        case 701: {
          // 处理模型信令
          switch (message.data.handleType) {
            case 'taskList': {
              const res = await ctx.controller.odm.taskList();
              this.sendMoldRes(
                {
                  taskList: res.data,
                },
                connect
              );
              break;
            }
            case 'taskNewCommit': {
              const res = await ctx.controller.odm.taskNewCommit(message.data);
              this.sendMoldRes(
                {
                  status: res.data,
                },
                connect
              );
              break;
            }
            case 'taskInit': {
              const res = await ctx.controller.odm.taskInit();
              this.sendMoldRes(
                {
                  status: res.data,
                },
                connect
              );
              break;
            }
            case 'taskAddRes': {
              const res = await ctx.controller.odm.taskAddRes(message.data);
              this.sendMoldRes(
                {
                  status: res.data,
                },
                connect
              );
              break;
            }
            case 'taskInfo': {
              const res = await ctx.controller.odm.taskInfo(message.data);
              this.sendMoldRes(
                {
                  status: res.data,
                },
                connect
              );
              break;
            }
            default:
              break;
          }
          break;
        }
        default:
          break;
      }
    }
  },
  /**
   * 回复701模型ws消息
   * @param {} data
   * @param {} connect
   */
  sendMoldRes(data, connect) {
    const resMessage = {
      type: 700,
      sub_type: 701,
      data,
    };
    connect.send(JSON.stringify(resMessage));
  },
};
